home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12828 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: socket problem ...
  5. Date: 21 Mar 1996 21:54:44 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4isj74$ato@news1.h1.usa.pipeline.com>
  8. References: <315181A4.7266@mitretek.org>
  9. NNTP-Posting-Host: 38.8.120.15
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 21, 1996 11:19:48 in article <socket problem ...>, 'Chris Irwin
  16. <cirwin@mitretek.org>' wrote: 
  17.  
  18.  
  19.  
  20. >I have a server daemon process that is leaving the socket bound upon  
  21. >exiting. It is actually a C++ program using the socket++-1.10 class  
  22. >library but uses the usual socket library calls. When I kill the server  
  23. >and try to restart it, it seems that the port is still in use. Basically  
  24. >the server does a fork() after the accept(). THe parent process closes  
  25. >the new socket and the child process closes the original socket does its  
  26. >thing and then exit() s. Any help would be greatly appreciated. 
  27. >Thanks in advance 
  28. Chris:  I tried to e-mail but it bounced, so I'll post it: 
  29. I do mostly TLI, but have done some raw socket programming also.  I  
  30. have found no problems of "stuck" ports since doing the following:  
  31.     
  32. void disconnect(int socket)  
  33.  {  
  34.    struct linger lx = { 1, 0 };  
  35.    if (setsockopt(socket, SOL_SOCKET, SO_LINGER, (char*)&lx, sizeof(lx)))  
  36.       myerrormessageandexit("error...");  
  37.    close(socket);  
  38.    exit(1);  
  39.   
  40. If setting the SO_LINGER doesn't do it for you, post your  
  41. question to comp.unix.programmer where guys like Rich Stevens  
  42. hang out (R Stevens is the author of Unix Network Programming).  
  43.   
  44. -- 
  45. Pete Grant 
  46. Kalevi, Inc. 
  47. Software Engineering & development
  48.